@echo off
echo ========================================
echo 课程中心端到端测试快速启动
echo ========================================

:: 检查当前目录
if not exist package.json (
    echo [错误] 请在前端项目根目录运行此脚本
    pause
    exit /b 1
)

:: 检查Node.js
node --version >nul 2>&1
if %errorlevel% neq 0 (
    echo [错误] 请先安装Node.js
    pause
    exit /b 1
)

echo [1/4] 检查并安装依赖...
npm install

echo [2/4] 检查Cypress...
npm list cypress >nul 2>&1
if %errorlevel% neq 0 (
    echo 安装Cypress...
    npm install cypress --save-dev
)

echo [3/4] 检查后端服务...
curl -s --connect-timeout 3 http://localhost:8080/actuator/health >nul 2>&1
if %errorlevel% neq 0 (
    echo [警告] 后端服务未运行，请先启动后端服务
    echo 启动方法: 进入backend\microservices目录，运行 docker-compose up -d
    echo.
    set /p continue="是否继续? (y/n): "
    if /i "%continue%" neq "y" exit /b 1
)

echo [4/4] 启动Cypress测试界面...
npx cypress open

echo.
echo 测试完成！
pause
